import logging
import unittest

from api.login_api import LoginApi


class TestLogin(unittest.TestCase):
    def test01_login_ok(self):
        print("test_login_ok")  # print打印的东西会放到测试报告中
        logging.info("test_login_ok")  # 日志打印的会放到控制台和日志文件中
        body = {
            "mobile": "13800000002",
            "password": "123456"
        }
        loginapi = LoginApi()
        resp = loginapi.login(body)
        json_data = resp.json()
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, json_data.get("success"))
        self.assertEqual(10000, json_data.get("code"))
        self.assertIn("成功", json_data.get("message"))

    def test02_user_err(self):
        print("test02_user_err")
        logging.info("test02_user_err")
        body = {
            "mobile": "13800022222",
            "password": "123456"
        }
        loginapi = LoginApi()
        resp = loginapi.login(body)
        json_data = resp.json()
        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, json_data.get("success"))
        self.assertEqual(20001, json_data.get("code"))
        self.assertIn("错误", json_data.get("message"))

    def test03_pwd_err(self):
        print("test03_pwd_err")
        logging.info("test03_pwd_err")
        body = {
            "mobile": "13800000002",
            "password": "123456abc"
        }
        loginapi = LoginApi()
        resp = loginapi.login(body)
        json_data = resp.json()
        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, json_data.get("success"))
        self.assertEqual(20001, json_data.get("code"))
        self.assertIn("错误", json_data.get("message"))
